<?php
/**
 * Created by PhpStorm.
 * User: xiao
 * Date: 2017/6/15
 * Time: 上午11:17
 */

namespace app\src\seller\logic;


use app\src\base\logic\BaseLogic;
use app\src\seller\model\SellerPromotion;

class SellerPromotionLogic extends BaseLogic
{
    protected function _init()
    {
        $this->setModel(new SellerPromotion());
    }

    /**
     * 添加商家活动
     * @param $seller_id
     * @param $entity
     * @return array
     */
    public function addPromotion($seller_id, $entity)
    {
        $data = [
            'seller_id' => $seller_id,
            'title' => $entity['title'],
            'detail' => $entity['detail'],
            'begin_time' => $entity['begin_time'],
            'end_time' => $entity['end_time'],
            'img' => isset($entity['img']) ? $entity['img'] : 0,
            'status' => 0
        ];

        $result = $this->add($data);

        return $result;
    }

    /**
     * 更新商家活动
     * @param $seller_id
     * @param $promotion_id
     * @param $entity
     * @return array
     */
    public function updatePromotion($seller_id, $promotion_id, $entity)
    {
        $map = [
            'seller_id' => $seller_id,
            'id' => $promotion_id
        ];
        $result = $this->save($map, $entity);

        return $result;
    }
}